#include "Command.h"

#include <iostream>

namespace IAlib
{
	Command::Command():m_type(COMMAND_UNDEF), m_num_target("target"), m_num_orig("orig"), m_data("data"), m_state(true)
	{}

        Command::Command(const Command &cmd)
        {
            m_type = cmd.m_type;
            m_num_target = cmd.m_num_target;
            m_num_orig = cmd.m_num_orig;
            m_data = cmd.m_data;
            m_state = cmd.m_state;
        }

	Command::~Command()
	{}

        QByteArray  Command::toByteArray() const
        {
            QByteArray byte_array;
            QDataStream data_stream(&byte_array, QIODevice::WriteOnly);
            data_stream << m_data;
            data_stream << m_num_orig;
            data_stream << m_num_target;
            data_stream << m_state;
            data_stream << m_type;

            return byte_array;
        }

        void Command::fromByteArray(QByteArray byte_array)
        {
            QDataStream data_stream(&byte_array, QIODevice::ReadOnly);
            data_stream >> m_data;
            data_stream >> m_num_orig;
            data_stream >> m_num_target;
            data_stream >> m_state;
            int temp;
            data_stream >> temp;
            m_type = (Command::CommandType) temp;

        }

}
